package base.iterator.vctor;

import com.sun.org.glassfish.gmbal.Description;

import java.util.Iterator;

public class WaterShelfIterator implements Iterator {

    /**
     * 这里最好是由于自己维护一个index 如果使用Watershlf方法提供来的耦合性比较大
     */
    private WaterShelf waterShelf;
    private int index;
    public WaterShelfIterator(WaterShelf waterShelf){
        this.waterShelf=waterShelf;
        this.index=0;
    }

    @Override
    public boolean hasNext() {
        if(index < waterShelf.getLength()){
            return true;
        }
        return false;
    }

   
    @Override
    public Object next() {
        Water water = waterShelf.getWater(index);
        index++;
        return water;
    }
}
